package de.openkanban.client.ui.presenter;

import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Response;
import com.smartgwt.client.util.SC;

import de.openkanban.client.ui.board.KanbanEditView;
import de.openkanban.client.util.RootPanel;
import de.openkanban.shared.dto.KanbanDto;

public class CreateKanbanRequestCallback implements RequestCallback {

	private KanbanEditView kanbanEditView;

	public CreateKanbanRequestCallback(KanbanEditView kanbanEditView) {
		this.kanbanEditView = kanbanEditView;
	}

	@Override
	public void onResponseReceived(Request request, Response response) {
		KanbanDto kanbanDto = new KanbanDto(response.getText());
		if (response.getStatusCode() < 300 && kanbanDto.isCallSuccessfull()) {
			RootPanel.main.getFooter().updateBoardHistoryData();
			RootPanel.main.getBoard().getWhiteBoardView().getActivityViewList().get(0).addKanban(kanbanDto);
			kanbanEditView.clear();
		} else {
			SC.say("Fehler: CreateKanbanRequestCall fehlgeschlagen!");
		}
	}

	@Override
	public void onError(Request request, Throwable exception) {

	}

}
